package mogowtools.client.fx;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;

public class Options {

	private int transition = 8;
	private int transitionType = 1;
	private int duration = 500;
	private boolean wait = true;
	private int unit = 1;
	private int fps = 50;
	
	private final static int TRANSITION_LINEAR = 0;
	private final static int TRANSITION_QUAD = 1;
	private final static int TRANSITION_CUBIC = 2;
	private final static int TRANSITION_QUART = 3;
	private final static int TRANSITION_QUINT = 4;
	private final static int TRANSITION_POW = 5;
	private final static int TRANSITION_EXPO = 6;
	private final static int TRANSITION_CIRC = 7;
	private final static int TRANSITION_SINE = 8;
	private final static int TRANSITION_BACK = 9;
	private final static int TRANSITION_BOUNCE = 10;
	private final static int TRANSITION_ELASTIC = 11;
	
	private final String[] TransitionString = {"linear", "Quad", "Cubic", "Quart", "Quint", "Pow",
								"Expo", "Circ", "Sine", "Back", "Bounce", "Elastic" };
	
	private final static int EASEIN = 0;
	private final static int EASEOUT = 1;
	private final static int EASEINOUT = 2;

	private final String[] transitionTypeString = {"easeIn", "easeOut", "easeInOut"};

	private final static int PERCENT = 0;
	private final static int PIXEL = 1;
	private final static int CM = 2;
	private final static int EM = 3;
	
	private final String[] unitString = {"%", "px", "cm", "em"};
	
	private List listeners = new ArrayList();
	
	public Options()
	{
	}
	
	public Options(int transition, int transitionType, int duration, boolean wait, int unit, int fps)
	{
		this.transition = transition;
		this.transitionType = transitionType;
		this.duration = duration;
		this.wait = wait;
		this.unit = unit;
		this.fps = fps;
	}
	
	public void addStyleListener(StyleListener s)
	{
		listeners.add(s);
	}
	
	private void onCancel()
	{
		GWT.log("onCancel", null);
		for (int i = 0; i < listeners.size(); i++)
			((StyleListener)listeners.get(i)).onCancel();
	}
	
	private void onStart()
	{
		GWT.log("onStart", null);
		for (int i = 0; i < listeners.size(); i++)
			((StyleListener)listeners.get(i)).onStart();
	}
	
	private void onComplete()
	{
		GWT.log("onComplete", null);
		for (int i = 0; i < listeners.size(); i++)
			((StyleListener)listeners.get(i)).onComplete();
	}
	
	public int getDuration() {
		return duration;
	}

	public void setDuration(int duration) {
		this.duration = duration;
	}

	public int getFps() {
		return fps;
	}

	public void setFps(int fps) {
		this.fps = fps;
	}

	public int getTransition() {
		return transition;
	}

	public void setTransition(int transition) {
		this.transition = transition;
	}

	public int getTransitionType() {
		return transitionType;
	}

	public void setTransitionType(int transitionType) {
		this.transitionType = transitionType;
	}

	public int getUnit() {
		return unit;
	}

	public void setUnit(int unit) {
		this.unit = unit;
	}

	public boolean isWait() {
		return wait;
	}

	public void setWait(boolean wait) {
		this.wait = wait;
	}
	
	public String getTransitionString()
	{
		return this.TransitionString[this.transition];
	}
	
	public String getTransitionTypeString()
	{
		return this.transitionTypeString[this.transitionType];
	}
	
	public String getUnitString()
	{
		return this.unitString[this.unit];
	}
	
	public native JavaScriptObject value()
	/*-{
		var transition = this.@mogowtools.client.fx.Options::getTransitionString()();
		var transitionType = this.@mogowtools.client.fx.Options::getTransitionTypeString()();
		var trans = "$wnd.Fx.Transitions."+transition+"."+transitionType;
		return  eval ("( { transition: "+eval(trans)+ 
				", duration: "+this.@mogowtools.client.fx.Options::getDuration()()+
				", unit: '"+this.@mogowtools.client.fx.Options::getUnitString()()+"'"+
				", wait: "+this.@mogowtools.client.fx.Options::isWait()()+
				", fps: "+this.@mogowtools.client.fx.Options::getFps()()+" } )";
				//+
				//", onStart: "+function() {alert('coucou');}+
				//", onComplete: "+function() {alert('coucou');}+
				//", onCancel: "+function() {alert('coucou');}+" } )");
	}-*/;
	
}
